<?php
namespace app\common\logic;

/**
 * 阿里短信
 */
class Msg 
{
    private $sign = '趣探究';
    private $app_key = 'LTAIKeOkyKEyHEST';
    private $app_secret = '7rm3qeG8beGmf1aemW8kCj3sJKb73m';
	 /**
     * [教师端验证码模板]
     * @param  [type] $phone [手机号]
     */
    public function index0($phone,$data=''){
        vendor("msg.api_demo.SmsDemo");
        $msg = new \SmsDemo($this->app_key,$this->app_secret);
        $response = $msg->sendSms(
            $this->sign, // 短信签名
            'SMS_142000374', // 短信模板编号
            $phone, // 短信接收者
            Array(  // 短信模板中字段的值
                "code" => $data
            ),
            "123"
        ); 
        if ($response->Code == 'OK') {
            $mg['code'] = 1;
            
        } else {
            $mg['code'] = 0;
            $mg['msg'] = $response->Message;
          
        } 
        return $mg;
    }
    /**
     * [发送完成模板]
     * @param  [type] $phone [手机号]
     */
    public function index1($phone,$data=''){
        vendor("msg.api_demo.SmsDemo");
        $msg = new \SmsDemo($this->app_key,$this->app_secret);
        $response = $msg->sendSms(
            $this->sign, // 短信签名
            'SMS_161597281', // 短信模板编号
            $phone, // 短信接收者
            Array(  // 短信模板中字段的值
                "url" => "mytask?id=".$data,
                "product"=>"dsd"
            ),
            "123"
        ); 
        if ($response->Code == 'OK') {
            $mg['code'] = 1;
            
        } else {
            $mg['code'] = 0;
            $mg['msg'] = $response->Message;
          
        } 
        //dump($phone);
        //dump($response);
        return $mg;
    }
    /**
     * [发送完成进行自拍]
     * @param  [type] $phone [手机号]
     */
    public function index2($phone,$data=''){
        vendor("msg.api_demo.SmsDemo");
        file_put_contents('./msg.txt', '自拍/n');
        vendor("msg.api_demo.SmsDemo");
        $msg = new \SmsDemo($this->app_key,$this->app_secret);
        $response = $msg->sendSms(
            $this->sign, // 短信签名
            'SMS_161591403', // 短信模板编号
            $phone, // 短信接收者
            Array(  // 短信模板中字段的值
                "product"=>"dsd",
               "url" => "start",
            ),
            "123"
        ); 
        if ($response->Code == 'OK') {
            $mg['code'] = 1;
            
        } else {
            $mg['code'] = 0;
            $mg['msg'] = $response->Message;
          
        } 
        return $mg;
    }
    /**
     * [发送查看素材]
     * @param  [type] $phone [手机号]
     */
    public function index3($phone,$data=''){

        vendor("msg.api_demo.SmsDemo");
        //file_put_contents('./msg.txt', '素材/n');
        vendor("msg.api_demo.SmsDemo");
        $msg = new \SmsDemo($this->app_key,$this->app_secret);
        $response = $msg->sendSms(
            $this->sign, // 短信签名
            'SMS_161592277', // 短信模板编号
            $phone, // 短信接收者
            Array(  // 短信模板中字段的值
                "product"=>"dsd",
                "url" => "mytask?id=".$data,
            ),
            "123"
        ); 
        if ($response->Code == 'OK') {
            $mg['code'] = 1;
            
        } else {
            $mg['code'] = 0;
            $mg['msg'] = $response->Message;
          
        } 
        //dump($response);
        return $mg;
    }
}

